// import count from '@dfeidao/atom-nodejs/db/count';
import query from '@dfeidao/atom-nodejs/db/query';
// import join from '@dfeidao/atom-nodejs/db/join-inner';
import format from '@dfeidao/atom-nodejs/dt/format';

interface Message {
	filter: {};
}
interface Star {
	role_no: string;
}
interface Data {
	role_no: string;
	create_time: string;
}
export default async function atom(msg: Message, action_id: string, session_id: string) {
	const systemid = '12';
	const { exec, prepare } = query(action_id, session_id, systemid);
	prepare('pub_user_connect', ['_id', 'usercode', 'role_no', 'pk_val', 'productid', 'search_field_val', 'create_time'], msg.filter, 200, 1, [], []);
	const [data] = await exec<Data>();
	data.forEach((item) => {
		item.create_time = item.create_time ? format(Number(item.create_time), 'yyyy-mm-dd') : '';
	});
	const r_nos = (data).map((s: Star) => {
		const r_no = s.role_no;
		return r_no;
	});
	const q = { role_no: { $in: r_nos } };

	prepare('pub_role', ['_id', 'role_name', 'role_no', 'role_type_id', 'productid', 'icon', 'create_time'], q, 200, 1, [], []);
	const [data2] = await exec<Data>();
	// debugger
	const detail = new Array();
	data.forEach((i) => {
		data2.forEach((j) => {
			if (i.role_no === j.role_no) {
				const obj = Object.assign(i, j);
				detail.push(obj);
			}
		});
	});

	// const c = count(action_id, session_id, systemid);
	// c.prepare('pub_user', msg.filter);
	// const [t] = await c.exec();
	return { dataArray: data };
}
